package com.temperate;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author:wesley
 */
public class TempKey implements WritableComparable<TempKey>{


    private Integer year;

    private Integer month;

    private double temperate;


    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public Integer getMonth() {
        return month;
    }

    public void setMonth(Integer month) {
        this.month = month;
    }

    public double getTemperate() {
        return temperate;
    }

    public void setTemperate(double temperate) {
        this.temperate = temperate;
    }

    @Override
    public int compareTo(TempKey o) {
        int r1 = Integer.compare(this.year, o.getYear());
        if (r1 == 0) {
            int r2 = Integer.compare(this.month , o.getMonth());
            if (r2 == 0){
                return Double.compare(this.temperate, o.getTemperate());
            } else {
                return r2;
            }
        } else  {
            return r1;
        }
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(this.year);
        dataOutput.writeInt(this.month);
        dataOutput.writeDouble(this.temperate);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.year = dataInput.readInt();
        this.month = dataInput.readInt();
        this.temperate = dataInput.readDouble();
    }
}
